<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../../rest.css">
    <style>
        .goodsList {
            width: 1220px;
            margin: 50px auto;
        }

        .goodsList li {
            width: 20%;
            float: left;
            margin: 20px 2.5%;
        }

        .goodsList .desc {
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .goodsList li img {
            width: 100%;
            display: block;
        }
    </style>
</head>

<body>
    <ul class="goodsList clear">
    </ul>
</body>


<script>
    var xhr = new XMLHttpRequest()
    xhr.open('get', '../json/goods.json')
    xhr.send()
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var res = xhr.responseText
            res = JSON.parse(res)

            var goodsList = document.getElementsByClassName('goodsList')[0]
            var html = ``
            res.forEach(item => {
                var { goodsId, goodsImg, goodsMsg, goodsName, goodsPrice } = item
                html += `
                <li> <a href="http://www.baidu.com">
                <img src="${goodsImg}"
                    alt="">
                <div class="price">￥${(goodsPrice.toFixed(2))}</div>
                <div class="desc">${goodsMsg}</div>
                </a></li>
                `
            })
            goodsList.innerHTML = html
        }
    }
</script>

</html>